using B.S.XZYData.Api.Read.Application.Command.DefectiveItemDistribution;
using B.S.XZYData.Domain.XZY;
using B.S.XZYData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace B.S.XZYData.Api.Read.Controllers
{
    /// <summary>
    /// 不良品项分布控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class DefectiveItemDistributionController : ControllerBase
    {
        private readonly IMediator _mediator;

        public DefectiveItemDistributionController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取不良品项分布分页数据
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="size">页大小</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="defectiveItemCode">不良品项编号</param>
        /// <param name="defectiveItemName">不良品项名称</param>
        /// <returns></returns>
        [HttpGet("GetDefectiveItemDistribution")]
        [Authorize]
        public async Task<ApiPageing<DefectiveItemDistribution>> GetDefectiveItemDistribution(
            [FromQuery] int index = 1,
            [FromQuery] int size = 30,
            [FromQuery] DateTime? startTime = null,
            [FromQuery] DateTime? endTime = null,
            [FromQuery] string? defectiveItemCode = null,
            [FromQuery] string? defectiveItemName = null)
        {
            var command = new GetDefectiveItemDistributionCommand
            {
                Index = index,
                Size = size,
                StartTime = startTime,
                EndTime = endTime,
                DefectiveItemCode = defectiveItemCode,
                DefectiveItemName = defectiveItemName
            };

            return await _mediator.Send(command);
        }
    }
}
